from django import template

register = template.Library()

@register.inclusion_tag('dashboard/services.html')
def show_services(host):
    services = {}
    for service in host.services:
        if host.services[service]['status'] == "0" and host.services[service]['monitor'] == "1":
            services[service] = True
        else:
            services[service] = False
    print services
    return { 'services': services, 'host': host}

@register.inclusion_tag('dashboard/load.html')
def show_localhost(host):
    localhost = {}
    try:
        localhost['localhost'] = host.services['localhost']['system']
    except KeyError:
        try:
            localhost['localhost'] = host.services['localhost']
        except KeyError:
            localhost = {}    
    return localhost

@register.inclusion_tag('dashboard/service_details.html')
def show_service_details(host, service):
    details = host.services[service]
    return {'details': details}
    

